package hflyeer.controller;

import hflyeer.base.BaseController;
import hflyeer.pojo.dto.UserDto;
import hflyeer.service.UserService;
import hflyeer.utils.LoginUserUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * IndexController
 *
 * @author hflyeer
 * @date 2021-06-03
 * @describe
 */
@Controller
public class IndexController extends BaseController {

    @Resource
    private UserService userService;

    /**
     * 登陆
     * @return
     */
    @RequestMapping(value = {"/index","/"})
    protected String toIndex(){
        return "index";
    }

    /**
     * 登入主页
     * @return
     */
    @RequestMapping("/main")
    protected String toMain(HttpServletRequest request){
        Integer userIdFromCookie = LoginUserUtil.releaseUserIdFromCookie(request);
        UserDto userDto = userService.selectById(userIdFromCookie);
        request.getSession().setAttribute("user",userDto);
        return "main";
    }

    /**
     * 登陆首页欢迎界面
     * @return
     */
    @RequestMapping("/welcome")
    protected String toWelcome(){
        return "welcome";
    }
}
